package com.project.xsf.controller;

import com.project.xsf.entity.MDesignProcedure;
import com.project.xsf.entity.MDesignProcedureDetails;
import com.project.xsf.service.MDesignProcedureDetailsService;
import com.project.xsf.service.MDesignProcedureService;
import com.project.xy.entity.DFile;
import com.project.xy.entity.DesignModule;
import com.project.xy.service.DFileService;
import com.project.xy.service.DesignModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/mDesignProcedureDetails")
public class MDesignProcedureDetailsController  {
    @Autowired
    private MDesignProcedureDetailsService mDesignProcedureDetailsService;
    @Autowired
    private MDesignProcedureService mDesignProcedureService;
    @Autowired
    private DesignModuleService designModuleService;
    @ResponseBody
    @PostMapping("/queryMDesignProcedureDetailsByPId.action")
    public List<MDesignProcedureDetails> queryMDesignProcedureDetailsByPIdAction(String pId){
//        System.out.println(pId);
        MDesignProcedure mDesignProcedure = mDesignProcedureService.selectByPrimaryKey(Integer.valueOf(pId));
//        System.out.println(mDesignProcedure);
        if(mDesignProcedure.getProcedureCheckTag().equals("S001-1")){
            List<MDesignProcedureDetails> mDesignProcedureDetails = mDesignProcedureDetailsService.queryMDesignProcedureDetailsByPId(Integer.valueOf(pId));
//        System.out.println(mDesignProcedureDetails);
            return mDesignProcedureDetails;
        }else{
            return null;
        }

    }
    @ResponseBody
    @PostMapping("/queryMDesignProcedureDetailsByPId1.action")
    public List<MDesignProcedureDetails> queryMDesignProcedureDetailsByPId1Action(String pId){
//        System.out.println(pId);
        MDesignProcedure mDesignProcedure = mDesignProcedureService.selectByPrimaryKey(Integer.valueOf(pId));
//        System.out.println(mDesignProcedure);
        List<MDesignProcedureDetails> mDesignProcedureDetails = mDesignProcedureDetailsService.queryMDesignProcedureDetailsByPId(Integer.valueOf(pId));
//        System.out.println(mDesignProcedureDetails);
        return mDesignProcedureDetails;

    }
    @ResponseBody
    @PostMapping("/queryMDesignProcedureDetailsByPId")
    public List<MDesignProcedureDetails> queryMDesignProcedureDetailsByPId(String pId){
//        System.out.println(pId);
        MDesignProcedure mDesignProcedure = mDesignProcedureService.selectByPrimaryKey(Integer.valueOf(pId));
//        System.out.println(mDesignProcedure);
        if(mDesignProcedure.getProcedureCheckTag().equals("S001-1")){
            List<MDesignProcedureDetails> mDesignProcedureDetails = mDesignProcedureDetailsService.queryMDesignProcedureDetailsByPId(Integer.valueOf(pId));
//        System.out.println(mDesignProcedureDetails);
            return mDesignProcedureDetails;
        }else{
            return null;
        }

    }
    @ResponseBody
    @PostMapping("/queryMDesignProcedureDetailsByPId1")
    public List<MDesignProcedureDetails> queryMDesignProcedureDetailsByPId1(Integer pId){
//        System.out.println(pId);

            List<MDesignProcedureDetails> mDesignProcedureDetails = mDesignProcedureDetailsService.queryMDesignProcedureDetailsByPId(pId);
//        System.out.println(mDesignProcedureDetails);
            return mDesignProcedureDetails;

    }
    @ResponseBody
    @PostMapping("/queryMDesignProcedureDetailsByProductId")
    public List<MDesignProcedureDetails> queryMDesignProcedureDetailsByProductId(@RequestBody Map<String,String> map){

            List<MDesignProcedureDetails> mDesignProcedureDetails = mDesignProcedureDetailsService.queryMDesignProcedureDetailsByProductId(map.get("productId"));
//        System.out.println(mDesignProcedureDetails);
            return mDesignProcedureDetails;

    }
    @ResponseBody
    @PostMapping("/queryMDesignProcedureDetailsById.action")
    public MDesignProcedureDetails queryMDesignProcedureDetailsById(String mDesignProcedureDetailId,Integer mDesignProcedureId,String productId){
        DesignModule designModule = designModuleService.queryByProductId(productId);
        if(designModule==null){
            return null;
        }else{
            if(designModule.getCheckTag().equals("S001-1")){
                MDesignProcedureDetails mDesignProcedureDetail = mDesignProcedureDetailsService.selectByPrimaryKey(Integer.valueOf(mDesignProcedureDetailId));
                return mDesignProcedureDetail;
            }else{
                return null;
            }
        }


    }
    @ResponseBody
    @PostMapping("/queryAndUpdateMDesignProcedureDetailsById.action")
    public MDesignProcedureDetails queryAndUpdateMDesignProcedureDetailsById(Integer mDesignProcedureDetailId,Integer mDesignProcedureId,String productId){
        DesignModule designModule = designModuleService.queryByProductId(productId);
        if(designModule==null){
            return null;
        }else{
            if(designModule.getCheckTag().equals("S001-1")){
                MDesignProcedure mDesignProcedure = mDesignProcedureService.selectByPrimaryKey(mDesignProcedureId);
                MDesignProcedureDetails mDesignProcedureDetail = mDesignProcedureDetailsService.queryAndUpdateMDesignProcedureDetailsById(mDesignProcedureDetailId,mDesignProcedure.getProductId(),productId);
                return mDesignProcedureDetail;
            }else{
                return null;
            }
        }


    }
    @ResponseBody
    @PostMapping("/queryAndUpdateMDesignProcedureDetailsById1.action")
    public MDesignProcedureDetails queryAndUpdateMDesignProcedureDetailsById1(Integer mDesignProcedureDetailId,Integer mDesignProcedureId,String productId){
        DesignModule designModule = designModuleService.queryByProductId(productId);
        if(designModule==null){
            return null;
        }else{
            MDesignProcedure mDesignProcedure = mDesignProcedureService.selectByPrimaryKey(mDesignProcedureId);
            MDesignProcedureDetails mDesignProcedureDetail = mDesignProcedureDetailsService.queryAndUpdateMDesignProcedureDetailsById(mDesignProcedureDetailId,mDesignProcedure.getProductId(),productId);
            return mDesignProcedureDetail;
        }


    }
}
